<?php

namespace App\model\customer;

use App\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * App\model\customer\Customer
 *
 * @property int $customer_id
 * @property string|null $address 地址
 * @property string|null $name 姓名
 * @property int|null $area_id 面积
 * @property int|null $hangye_id 行业
 * @property int|null $peidian_id
 * @property int|null $xuqiu 0 求购 1租
 * @property int|null $soure_id
 * @property int|null $ower_user_id
 * @property int|null $create_user_id
 * @property \Illuminate\Support\Carbon|null $deleted_at
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property string|null $desc
 * @property int|null $huanping_id 环评id
 * @property int|null $status 状态
 * @method static bool|null forceDelete()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer newQuery()
 * @method static \Illuminate\Database\Query\Builder|\App\model\customer\Customer onlyTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer query()
 * @method static bool|null restore()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereAddress($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereAreaId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereCreateUserId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereCustomerId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereDesc($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereHangyeId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereHuanpingId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereOwerUserId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer wherePeidianId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereSoureId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereXuqiu($value)
 * @method static \Illuminate\Database\Query\Builder|\App\model\customer\Customer withTrashed()
 * @method static \Illuminate\Database\Query\Builder|\App\model\customer\Customer withoutTrashed()
 * @mixin \Eloquent
 * @property string|null $telephone
 * @property int|null $xuqiu_id 0 求购 1租
 * @property int|null $source_id
 * @property int|null $wuye_id
 * @property int|null $xiaofang_id
 * @property string|null $code 编号
 * @property-read \App\model\customer\CustomerArea|null $area
 * @property-read \App\model\customer\CustomerHangye|null $hangye
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereSourceId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereTelephone($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereWuyeId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereXiaofangId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereXuqiuId($value)
 * @property string|null $area_format
 * @property string|null $hangye_format
 * @property string|null $peidian_format
 * @property string|null $xuqiu_format
 * @property string|null $source_format
 * @property string|null $huanping_format
 * @property string|null $wuye_format
 * @property string|null $xiaofang_format
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereAreaFormat($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereHangyeFormat($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereHuanpingFormat($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer wherePeidianFormat($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereSourceFormat($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereWuyeFormat($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereXiaofangFormat($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereXuqiuFormat($value)
 * @property int|null $department_id
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereDepartmentId($value)
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\model\Customer\CustomerFollow[] $follow
 * @property-read int|null $follow_count
 * @property int|null $group_id
 * @property-read \App\model\customer\CustomerSecondDepart|null $depart
 * @property-read \App\User|null $owner
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\model\customer\CustomerRecords[] $records
 * @property-read int|null $records_count
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereGroupId($value)
 * @property int|null $big_part_id
 * @property string|null $create_user_name 创建人名称
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereBigPartId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereCreateUserName($value)
 * @property int|null $follow_status 跟进状态
 * @property-read \App\model\customer\CustomerBigDepart|null $bigDepart
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereFollowStatus($value)
 * @property string|null $record_time 最后跟进时间
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\customer\Customer whereRecordTime($value)
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\model\customer\CustomerMobile[] $mobiles
 * @property-read int|null $mobiles_count
 * @property-read \App\User|null $creater
 */
class Customer extends Model
{
    protected $primaryKey='customer_id';
    protected $table='customer';
    protected $fillable = ['name','telephone','address','area_id','hangye_id','peidian_id',
        'xuqiu_id','source_id','huanping_id','wuye_id','xiaofang_id','desc','create_user_id'];


    const zhongdian=1;
    const kegenjin=2;
    const wuxiao=3;
    const kechongfen=0;
    const zanhuan=4;
    const yizu=5;
    const NO_FOLLOW=0;
    const FOLLOW_TO_GROUP=1;
    const FOLLOW_TO_USER=2;
    public static  $statusMap=[
      self::NO_FOLLOW=>'未分配',
      self::FOLLOW_TO_GROUP=>'分配到组',
      self::FOLLOW_TO_USER=>'已分配'
    ];
    public static  $followMap=[
        self::zhongdian=>'重点跟进',
        self::kegenjin=>'可跟进',
        self::wuxiao=>'无效',
        self::kechongfen=>'可重分',
        self::zanhuan=>'暂缓',
        self::yizu=>'已租',
    ];
    public function area(){
        return $this->belongsTo(CustomerArea::class,'area_id');
    }
    static function getCode(Customer $customer){
        return \Illuminate\Support\Carbon::now()->format("YmdHis").$customer->customer_id;
    }
    public function hangye(){
        return $this->belongsTo(CustomerHangye::class,'hangye_id');
    }
    public function depart(){
        return $this->belongsTo(CustomerSecondDepart::class,'group_id');
    }
    public function bigDepart(){
        return $this->belongsTo(CustomerBigDepart::class,'big_part_id');
    }
    public function owner(){
        return $this->belongsTo(User::class,'ower_user_id');
    }
    public function creater(){
        return $this->belongsTo(User::class,'create_user_id');
    }
    /**
     * 跟进内容
     */
    public function  records(){
        return $this->hasMany(CustomerRecords::class,'customer_id');
    }
    public function mobiles(){
        return $this->hasMany(CustomerMobile::class,'customer_id');
    }
}
